package com.gitee.wsl.result.process

import com.gitee.wsl.result.EntryResult
import com.gitee.wsl.result.StateEntryResult

/**
 * Returns the [value][EntryResult.value] if this result [is ok][EntryResult.isOk], otherwise `null`.
 *
 * - Elm: [Result.toMaybe](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#toMaybe)
 * - Rust: [Result.ok](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok)
 */
fun <V, E,S> StateEntryResult<V, E, S>.getState(): S? {
    return when {
        isStateValue -> stateValue
        else -> null
    }
}